package com.bdq.common.utils;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.bdq.common.constants.Constant;
import com.bdq.common.entity.UserContext;

/**
 * @author malei
 * @date 2024-05-04 11:58
 */
public class UserContextUtil {

    /**
     *
     * @param token
     * @return
     */
    public static UserContext getLoginUserContext(String token){
        if (StrUtil.isBlank(token)) {
            return null;
        }
        String userStr = RedisUtil.get(String.format(Constant.RedisKeyTemplate.USER_CONTEXT, TokenUtil.getUserMobile(token)));
        if (StrUtil.isBlank(userStr)) {
            return null;
        }
        return JSON.parseObject(userStr, UserContext.class);
    }
}
